package com.infinit.selfhelp.common.base

import android.app.Application
import android.util.Log
import com.drake.net.BuildConfig
import com.drake.net.NetConfig
import com.drake.net.okhttp.setConverter
import com.drake.net.okhttp.setDebug
import com.drake.net.okhttp.trustSSLCertificate
import com.infinit.selfhelp.common.net.converter.GsonConverter
import com.infinit.selfhelp.common.net.interceptor.LoggingInterceptor
import java.util.concurrent.TimeUnit

open class BaseApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        initNet()
    }
    open fun initNet() {
        LoggingInterceptor()
        NetConfig.initialize("", this) {
            // 超时配置, 默认是10秒, 设置太长时间会导致用户等待过久
            connectTimeout(30, TimeUnit.SECONDS)
            readTimeout(30, TimeUnit.SECONDS)
            writeTimeout(30, TimeUnit.SECONDS)
            setDebug(BuildConfig.DEBUG)
            setConverter(GsonConverter())
            addInterceptor(LoggingInterceptor())
            trustSSLCertificate()
        }
        Log.d("--net-base", NetConfig.host)
    }
}
